home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase v5.5 / CUSTOM.PAK / TABBOX.CC < prev    next >
Encoding:
Text File  |  1995-07-18  |  6.2 KB  |  175 lines

  1. *******************************************************************************
  2. *  FILE:         Tabbox.cc
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         1/94
  7. *
  8. *  UPDATED:      6/95
  9. *
  10. *  REVISION:     $Revision:   1.3  $
  11. *
  12. *  VERSION:      Visual dBASE
  13. *
  14. *  DESCRIPTION:  This files contains various Tabbox custom controls that can be
  15. *                used in Visual dBASE forms.  Each control is contained in
  16. *                a separate class.
  17. *
  18. *                Current Controls are:
  19. *
  20. *                   PageTabBox    -- Tabbox for keeping track of a forms' pages
  21. *
  22. *                   SearchTabBox  -- Tabbox for alphabetical searches
  23. *
  24. *  PARAMETERS:   None
  25. *
  26. *  CALLS:        None
  27. *
  28. *  USAGE:        When creating a form, select the "Set Up Custom Controls"
  29. *                menu from the "File" menu.  Then select "Add" VBX control
  30. *                from the "Set Up Custom Controls" dialog. Select this file
  31. *                from the file selection dialog that comes up.
  32. *                The controls in this file will be available on the "Custom"
  33. *                page of the "Controls" window.
  34. *
  35. ********************************************************************************
  36.  
  37. *******************************************************************************
  38. *******************************************************************************
  39. class PageTabBox(f,n) of TabBox(f,n) custom
  40.  
  41. *  CONTROL:      Page Tabbox
  42. *
  43. *  DESCRIPTION:  This control allows using tabs to switch between form
  44. *                pages
  45. *******************************************************************************
  46.  
  47.    this.PageNo = 0
  48.    this.ColorNormal = "N/W"
  49.    this.Visible = .F.                  && Invisible until dataSource is defined
  50.    this.OnOpen = CLASS::PageTabBox_OnOpen
  51.    this.OnSelChange = CLASS::PageTabBox_OnSelChange
  52.  
  53.    *** Protected properties
  54.    protect pageNo, visible
  55.  
  56.  
  57.    ****************************************************************************
  58.    Procedure PageTabBox_OnOpen
  59.    ****************************************************************************
  60.    local i, pageCnt
  61.  
  62.    pageCnt = form.PageCount()
  63.    this.promptAr = new array(pageCnt)     && Create array of prompts
  64.    for i = 1 to pageCnt
  65.       this.promptAr[i] = "Page " + ltrim(str(i))
  66.    next i
  67.  
  68.    this.dataSource = "array this.promptAr"
  69.    this.visible = .T.
  70.  
  71.    ****************************************************************************
  72.    Procedure PageTabBox_OnSelChange
  73.    ****************************************************************************
  74.  
  75.    if this.curSel <= form.PageCount()
  76.       form.pageNo = this.curSel
  77.    endif
  78.  
  79. endclass
  80.  
  81.  
  82. *******************************************************************************
  83. *******************************************************************************
  84. class SearchTabBox(f,n) of TabBox(f,n) custom
  85.  
  86. *  CONTROL:      Letter Search Tabbox
  87. *
  88. *  DESCRIPTION:  This control allows SEEKing for the key value that starts
  89. *                with the selected letter, or LOCATing the value of the
  90. *                last selected control, which begins with the selected letter.
  91. *******************************************************************************
  92.  
  93.    this.Height = 1
  94.    this.Left = 0
  95.    this.PageNo = 1
  96.    this.Width = 125
  97.    this.Anchor = 0            && So doesn't have to stay at the bottom
  98.    this.ColorNormal = "N/W"
  99.    this.Visible = .F.         && Invisible until dataSource assigned
  100.  
  101.    this.charField = .F.       && For storing name of a char field if no key
  102.    this.tableHasCharField = .T.
  103.  
  104.    this.OnOpen = CLASS::SearchTabBox_OnOpen
  105.    this.OnSelChange = CLASS::SearchTabBox_OnSelChange
  106.  
  107.    *** Protected properties
  108.    protect charField, tableHasCharField
  109.  
  110.  
  111.    ****************************************************************************
  112.    Procedure SearchTabBox_OnOpen
  113.    ****************************************************************************
  114.  
  115.    #define MAX_LETTERS 26
  116.    local i
  117.  
  118.    this.promptAr = new array(MAX_LETTERS)
  119.    for i = 1 to MAX_LETTERS
  120.                                             && Capital letters, starting at "A"
  121.       this.promptAr[i] = chr(asc("A") + i - 1)
  122.    next i
  123.  
  124.    this.dataSource = "array this.promptAr"
  125.    this.SearchTabBox_OnSelChange()          && Search for first key
  126.    this.visible = .T.
  127.  
  128.  
  129.    ****************************************************************************
  130.    Procedure SearchTabBox_OnSelChange
  131.    ****************************************************************************
  132.    private saveExact, saveNear, saveRecNo, i, fCount, charField, foundCharField
  133.  
  134.    saveExact = set("exact")
  135.    set exact off
  136.  
  137.    if .not. empty(key())                      && If table is indexed
  138.       saveNear = set("near")
  139.       set near on                             && If not found, go to nearest
  140.       seek this.promptAr[this.curSel]         && match
  141.       set near &saveNear
  142.    else                                       && If table is not indexed
  143.       if this.tableHasCharField .and. type("this.charField") = "L"
  144.                                               && If don't have char field yet
  145.          fCount = fCount()
  146.          i = 1
  147.          this.tableHasCharField = .F.
  148.          do while .not. this.tableHasCharField .and. i <= fCount
  149.                                               && Search until found char field
  150.                                               && or got to last field
  151.             this.tableHasCharField = (type("field(i)") == "C")
  152.             i = i + 1
  153.          enddo
  154.          if this.tableHasCharField            && If a character field was found
  155.             this.charField = field(i)         && Save the field name
  156.          else
  157.             * Will not look for char field next time
  158.          endif
  159.       endif
  160.       if this.tableHasCharField
  161.          charField = this.charField           && Temporary storage for macro
  162.          saveRecNo = recno()
  163.          locate for upper(&charField) = upper(this.promptAr[this.curSel])
  164.          if .not. found()                     && If not found,
  165.             goto saveRecNo                    && go to previous record
  166.          endif
  167.       endif
  168.    endif
  169.  
  170.    set exact &saveExact
  171.  
  172. endclass
  173.  
  174.  
  175.